package IteratorAndComposite.composite.entry;

import IteratorAndComposite.composite.interfaces.MenuComponent;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @Author: pengzx
 * @Description:
 * @Date: 17:53 2017/9/22
 * @Modified by: 1.0
 */
public class Menu extends MenuComponent {
    /**
     * 菜单可以有任意数量的子集，这些子集必须属于MenuComponent类
     */
    private ArrayList<MenuComponent> menuComponents = new ArrayList<>(0);
    private String name;
    private String description;

    public Menu(String name, String description)
    {
        this.name = name;
        this.description = description;
    }

    @Override
    public void add(MenuComponent menuComponent)
    {
        menuComponents.add(menuComponent);
    }

    @Override
    public void remove(MenuComponent menuComponent)
    {
        menuComponents.remove(menuComponent);
    }

    @Override
    public void print()
    {
        System.out.print("  "+getName());
        System.out.println(",  "+getDescription());
        System.out.println("-------------------------");

        Iterator iterator = menuComponents.iterator();
        while (iterator.hasNext()){
            MenuComponent menuComponent = (MenuComponent) iterator.next();
            menuComponent.print();
        }
    }

    @Override
    public Iterator createIterator()
    {

        return null;
    }

    @Override
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }
}
